Test requested --target from source of truth
authorAlex Crichton <alex@alexcrichton.com>
Fri, 30 Sep 2016 20:07:37 +0000 (13:07 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 30 Sep 2016 20:07:37 +0000 (13:07 -0700)
We skip doc tests for any cross compiles (as they don't work) but to detect a
cross compile we checked `--target` but forgot to check other locations like
`CARGO_BUILD_TARGET` or `[build.target]`. This alters the check to ensure that
it verifies from the source of truth whether a cross compilation happened or
not.

Closes #3143

src/cargo/ops/cargo_rustc/compilation.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/ops/cargo_test.rs

index 71263450d366fc04972231696679cf18d44ea240..23f0a044fcfc21ce7e90775e7ed467b574875e05 100644 (file)
@@ -44,6 +44,8 @@ pub struct Compilation<'cfg> {
     /// Features enabled during this compilation.
     pub cfgs: HashSet<String>,
 
+    pub target: String,
+
     config: &'cfg Config,
 }
 
@@ -60,6 +62,7 @@ impl<'cfg> Compilation<'cfg> {
             to_doc_test: Vec::new(),
             cfgs: HashSet::new(),
             config: config,
+            target: String::new(),
         }
     }
 
index 59d1ec57f632267b47826bb3ead91f83a32815b7..7f02b3138d69bc9de976659fa604569d537db4bf 100644 (file)
@@ -159,6 +159,7 @@ pub fn compile_targets<'a, 'cfg: 'a>(ws: &Workspace<'cfg>,
             cx.compilation.native_dirs.insert(dir.clone());
         }
     }
+    cx.compilation.target = cx.target_triple().to_string();
     Ok(cx.compilation)
 }
 
index 44a51be30174c99147a605a350f3a19dd5a2a2b5..e8f155a345bcc93353f422f9fb6b713125c9be68 100644 (file)
@@ -116,10 +116,8 @@ fn run_doc_tests(options: &TestOptions,
     let config = options.compile_opts.config;
 
     // We don't build/rust doctests if target != host
-    if let Some(target) = options.compile_opts.target {
-        if try!(config.rustc()).host != target {
-            return Ok(errors);
-        }
+    if try!(config.rustc()).host != compilation.target {
+        return Ok(errors);
     }
 
     let libs = compilation.to_doc_test.iter().map(|package| {